const pool = require('../utils/mysql')

function handleUploadData(req, res) {
    req.on('data', chunk => {
        let temperatureObj = JSON.parse(chunk.toString())
        console.log(temperatureObj)
        pool.query('insert into temperature_data values(?, ?, now())', [null, temperatureObj.temperature], (err, result) => {
            if (err) {
                throw err
            }
            console.log(result)
        })
        res.send('ok')
    })

}

module.exports = handleUploadData

